#cmake_minimum_required(VERSION 2.6)

#project(${DETECT_NAME})

#add_definitions(-std=c++11)

#message(DEBUG ${PROJECT_SOURCE_DIR})

#include_directories(${PROJECT_SOURCE_DIR}/include)
# include and link dirs of cuda and tensorrt, you need adapt them if yours are different
# cuda
include_directories(/usr/local/cuda/include)
include_directories(${SOLUTION_DIR})
include_directories(/usr/local/cuda/include/crt)
link_directories(/usr/local/cuda/lib64)
# tensorrt
include_directories(/usr/include/x86_64-linux-gnu/)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/YoloV5)
link_directories(/usr/lib/x86_64-linux-gnu/)
include_directories(${TRT_ROOT_DIR}/include)
link_directories(${TRT_ROOT_DIR}/lib)
link_directories(${SOLUTION_DIR}/libs/${PROJECT_NAME})

if(BUILD_INT8)
	add_definitions(-DUSE_INT8)
	message("Build Engine as INT8")
	message("INT8_CALIBRATE_DATASET_PATH: " ${INT8_CALIBRATE_DATASET_PATH})
	configure_file(${SOLUTION_DIR}/include/fastrt/config.h.in ${SOLUTION_DIR}/include/fastrt/config.h @ONLY)
elseif(BUILD_FP16)
	add_definitions(-DUSE_FP16)
	message("Build Engine as FP16")
else()
	message("Build Engine as FP32")
endif()

aux_source_directory(YoloV5 YOLODET_SOURCE)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}-Wall -pthread -O3 -Wno-deprecated-gpu-targets") 
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}-Wall -pthread -O3")
set(CUDA_NVCC_FLAGS
#		-gencode arch=compute_20,code=sm_20;
#		-gencode arch=compute_20,code=sm_21;
#		-gencode arch=compute_30,code=sm_30;
#		-gencode arch=compute_35,code=sm_35;
#		-gencode arch=compute_50,code=sm_50;
#		-gencode arch=compute_52,code=sm_52;
		-gencode arch=compute_60,code=sm_60;
		-gencode arch=compute_61,code=sm_61;
		-gencode arch=compute_61,code=compute_61;
		-gencode arch=compute_70,code=compute_70;
		-gencode arch=compute_72,code=compute_72;
		-gencode arch=compute_75,code=compute_75;
#		-gencode arch=compute_80,code=compute_80;
		-G;-g)
cuda_add_library(${DETECT_NAME} SHARED
	${YOLODET_SOURCE}
	${CMAKE_CURRENT_SOURCE_DIR}/detection.cpp
	${CMAKE_CURRENT_SOURCE_DIR}/YoloV5Detection.cpp
)
	
target_link_libraries(${DETECT_NAME} nvinfer cudart ${OpenCV_LIBS})
install(TARGETS ${DETECT_NAME} LIBRARY DESTINATION ${SOLUTION_DIR}/libs/${PROJECT_NAME})
